<template>
	<view>
		<u-tabs class="jointab" :list="list" :current="current" :is-scroll="false"  lineHeight="4"
			:itemStyle="{flex:'1',height:'60rpx',}" @change="change"></u-tabs>
		<view class="activity">
			<!-- 全部活动 -->
			<view v-if="current ==0&&activitylist.length >=1" class="activity-main" v-for="(item,index) in activitylist"
				:key="index" @click="toActivityDetails(item)">
				<view class="main-img">
					<u--image :showLoading="true" :src="item.picUrl" width="100%" height="140px"></u--image>
				</view>
				<!-- 活动状态 -->
				<view class="main-content">
					<view class="content-right">
						{{item.title}}
					</view>
					<view v-if="item.state==0">
						<view class="area-rightA">未开始</view>
					</view>
					<view v-if="item.state==1">
						<view class="area-rightB">进行中</view>
					</view>
					<view v-if="item.state==2">
						<view class="area-rightC">已结束</view>
					</view>
				</view>
				<view class="time">
					<view class="main-time">报名时间：{{item.creatTime}}</view>
					<view class="time-right">
						<u-button style="height: 50rpx;" type="primary" text="查看详情" @click="enlist"></u-button>
					</view>
				</view>
			</view>
			<view v-if="current ==0&&activitylist.length ==0">
				<view class="tabsContent">
					<u-empty mode="data" width="280" height="280" textSize="28"
						icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂未参加任何活动"></u-empty>
				</view>
			</view>
			<!-- 我的活动 -->
			<view v-if="current ==1&&myactivitylist.length >=1" class="activity-main"
				v-for="(item,index) in myactivitylist" :key="index" @click="toActivityDetails(item)">
				<view class="main-img">
					<u--image :showLoading="true" :src="item.picUrl" width="100%" height="140px"></u--image>
				</view>
				<!-- 活动状态 -->
				<view class="main-content">
					<view class="content-right">
						{{item.title}}
					</view>
					<view v-if="item.state==0">
						<view class="area-rightA">未开始</view>
					</view>
					<view v-if="item.state==1">
						<view class="area-rightB">进行中</view>
					</view>
					<view v-if="item.state==2">
						<view class="area-rightC">已结束</view>
					</view>
				</view>
				<view class="time">
					<view class="main-time">报名时间：{{item.creatTime}}</view>
					<view class="time-right">
						<u-button style="height: 50rpx;" type="success" text="已报名" @click="yijoin"></u-button>
					</view>
				</view>
			</view>
			<view v-if=" current == 1 && myactivitylist.length ==0 ">
				<view class="tabsContent">
					<u-empty mode="data" width="280" height="280" textSize="28"
						icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂未参加任何活动"></u-empty>
				</view>

			</view>
		</view>

	</view>
</template>

<script>
	import api from '@/api/api.js';
	export default {
		data() {
			return {
				list: [{
					name: '全部活动',
				}, {
					name: '我的活动',
				}],
				pageNum: 1,
				pageSize: 10,
				current: 0,
				activitylist: [],
				myactivitylist: [],
				activityRecord: null,
				AcyivityList: null
			}
		},
		onShow() {
			const that = this;
			this.activitylist = []
			this.pageNum = 1
			this.num = null
			this.getActivityList()

		},
		onLoad(e) {
			if (e.current == 1) {
				this.current = e.current
				this.pageNum = 1
				this.myactivitylist = []
				this.num = null
				this.getmyActivityList()
			}

		},
		onReachBottom(){
		    uni.$u.toast('已经到底啦')
		},
		// 下拉刷新
		onPullDownRefresh() {
			if (this.current == 0) {
				const _that = this
				_that.pageNum = 1
				this.activitylist = []
				this.pageNum = 1
				this.num = null
				setTimeout(function() {
					uni.stopPullDownRefresh();
					_that.getActivityList();
				}, 500);

			} else {
				const _that = this
				_that.pageNum = 1
				this.myactivitylist = []
				this.pageNum = 1
				this.num = null
				setTimeout(function() {
					uni.stopPullDownRefresh();
					_that.getmyActivityList();
				}, 500);
			}


		},
		methods: {
			//获取全部活动
			getActivityList() {
				let housingId = uni.getStorageSync('housingId')
				api.getActivity({
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					housingId: housingId,
				}).then(res => {
					console.log(res)
					this.activitylist = res.data.rows
					this.num = Math.ceil(res.data.total / this.pageSize) //总条数除一页多少条向上取整
					this.pageNum++
				})
			},
			//获取我的活动
			getmyActivityList() {
				let housingId = uni.getStorageSync('housingId')
				let userInfo = uni.getStorageSync('userInfo')
				api.getmyActivity({
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					userId: userInfo.id,
					housingId: housingId,
				}).then(res => {
					this.myactivitylist = res.data.data
					this.getRecordList()
					this.num = Math.ceil(res.data.total / this.pageSize) //总条数除一页多少条向上取整
					this.pageNum++
				})
			},
			//获取活动记录列表
			getRecordList() {
				let userInfo = uni.getStorageSync('userInfo')
				api.getAcyivityRecord({
					userId: userInfo.id,
					exerciseId: this.id,
				}).then(res => {
					console.log(res)
					this.activityRecord = res.data.rows

				})
			},
			// 活动
			change(e) {
				this.current = e.index;
				if (this.current == 0) {
					this.getActivityList();
				} else {
					this.getmyActivityList();
				}
			},
			// 跳转活动详情
			toActivityDetails(item) {
				this.state = item.state
				uni.$u.route({
					url: '/pages/activity/details',
					params: {
						id: item.id,
						state: this.state
					}
				})
			},
			// 报名
			enlist(item) {
				this.state = item.state
				uni.$u.route({
					url: '/pages/activity/details',
					params: {
						id: item.id,
						state: this.state
					}
				})
			},
			// 查看详情
			yijoin(item) {
				this.state = item.state
				uni.$u.route({
					url: '/pages/activity/details',
					params: {
						id: item.id,
						state: this.state
					}
				})
			}
		}
	}
</script>
<style>
	.jointab .u-tabs__wrapper__nav .u-tabs__wrapper__nav__line {
		transform: translate(100%) !important;
	}
</style>
<style lang="scss" scoped>
	.jointab {
		width: 100%;
		display: flex;
		font-size: 28rpx;
		background-color: #FFFFFF;
		height: 60rpx;

	}

	.tabsContent {
		// margin-top: 16rpx;
		width: 100%;
		background-color: #FFFFFF;
		height: 600rpx;
	}

	.activity {
		padding: 16rpx;
		width: calc(100%-32rpx);
		border-radius: 20rpx;
		margin-top: 8rpx;

		.activity-top {
			display: flex;

			.left-top {
				font-size: 32rpx;
				font-weight: bold;
				border-left: #17abe3 10rpx solid;
				padding-left: 12rpx;
				margin-bottom: 20rpx;
			}

			.right-top {
				font-size: 32rpx;
				// background-color: #1dd1ff;
				color: #007AFF;
				font-weight: bold;
				padding-left: 20rpx;
				margin-bottom: 20rpx;
				margin-left: auto;
			}
		}

		.content-left {
			width: 25%;
			line-height: 56rpx;
			text-align: center;
			font-size: 28rpx;
			background-color: #37c0ff;
			color: #FFFFFF;
			border-radius: 20rpx;
			z-index: 999;
			position: relative;
			top: -450rpx;
			left: -120rpx;
		}

		// 活动内容
		.activity-main {
			padding: 32rpx 32rpx;
			width: calc(100%-64rpx);
			margin-bottom: 32rpx;
			background-color: #fff;
			border-radius: 8rpx;
			box-shadow: 0rpx 1rpx 8rpx 0rpx #e5e5e5;

			.main-content {
				padding: 10rpx 0rpx;
				display: flex;

				.content-right {
					width: 90%;
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					font-size: 28rpx;
				}

				// .area-right {
				// 	width: 100rpx;
				// 	height: 40rpx;
				// 	line-height: 40rpx;
				// 	font-size: 24rpx;
				// 	text-align: center;
				// 	background-color: #a4a7a7;
				// 	color: #fff;
				// 	border-radius: 10rpx;
				// }
				.area-rightA {
					width: 100rpx;
					height: 40rpx;
					line-height: 40rpx;
					font-size: 24rpx;
					text-align: center;
					background-color: #a4a7a7;
					color: #fff;
					border-radius: 10rpx;
				}

				.area-rightB {
					width: 100rpx;
					height: 40rpx;
					line-height: 40rpx;
					font-size: 24rpx;
					text-align: center;
					background-color: #fc0010;
					color: #fff;
					border-radius: 10rpx;
				}

				.area-rightC {
					width: 100rpx;
					height: 40rpx;
					line-height: 40rpx;
					font-size: 24rpx;
					text-align: center;
					background-color: #fea417;
					color: #FFFFFF;
					border-radius: 10rpx;
				}
			}


			.time {
				display: flex;
				position: relative;
				justify-content: space-between;
				top: 10rpx;

				.main-time {
					padding: 1rpx 0rpx;
					font-size: 24rpx;
					color: #838487;
				}

				.time-right {
					width: 168rpx;
				}
			}

		}
	}

	.Wactivity {
		height: 200rpx;
		background-color: #FFFFFF;
		color: #9b9e9e;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>
